#include "InfoBar.h"
#include "ResourceManager.h"
#include <d3dx9.h>

InfoBar::InfoBar(float x, float y,int marioLife, int point, float totaltime)
{
	_x = x;
	_y = y;
	_life=marioLife;
	_point=point;
	_totalTime=totaltime;
	_startTime=GetTickCount();
	_remainTime=totaltime;
}

InfoBar::~InfoBar(void)
{
		
}

void InfoBar::Update()
{
	float delta=GetTickCount()-_startTime;

	_remainTime=_totalTime-delta/1000;
}


void InfoBar:: Render()
{
	ResourceManager *_ResourceManager=ResourceManager::GetInstance();

	_spriteHandler->Draw(_ResourceManager->GetTexture(_ResourceManager->TextureName.Infobar)->Get_Texture(),0,0,&D3DXVECTOR3(0,0,0),D3DCOLOR_XRGB(253, 253, 253));



	// Ve them cac text block

	ID3DXFont *g_font=NULL;

	HRESULT hr;

	hr=D3DXCreateFont(_d3ddv,     //D3D Device

                     25,               //Font height

                     0,                //Font width

                     FW_NORMAL,        //Font Weight

                     1,                //MipLevels

                     false,            //Italic

                     DEFAULT_CHARSET,  //CharSet

                     OUT_DEFAULT_PRECIS, //OutputPrecision

                     ANTIALIASED_QUALITY, //Quality

                     DEFAULT_PITCH|FF_DONTCARE,//PitchAndFamily

                     L"Arial",          //pFacename,

                     &g_font);         //ppFont

   RECT font_rect1;
   font_rect1.left=100;
   font_rect1.top=10;
   font_rect1.right=font_rect1.left+50;
   font_rect1.bottom=font_rect1.top+50;

   RECT font_rect2;
   font_rect2.left=200;
   font_rect2.top=10;
   font_rect2.right=font_rect2.left+50;
   font_rect2.bottom=font_rect2.top+50;

   RECT font_rect3;
   font_rect3.left=300;
   font_rect3.top=10;
   font_rect3.right=font_rect3.left+50;
   font_rect3.bottom=font_rect3.top+50;

   tstringstream lifeString;
   lifeString << _life;

   tstringstream pointString;
   pointString << _point;

   tstringstream remainTimeString;
   remainTimeString << _remainTime;

   g_font->DrawTextA(_spriteHandler,        //pSprite

								lifeString.str().c_str(),  //pString

								-1,          //Count

                                &font_rect1,  //sssspRect

                                DT_LEFT|DT_NOCLIP,0xFFFFFFFF//Format,

                                ); //Color 

    g_font->DrawTextA(_spriteHandler,        //pSprite

								pointString.str().c_str(),  //pString

								-1,          //Count

                                &font_rect2,  //pRect

                                DT_LEFT|DT_NOCLIP,0xFFFFFFFF//Format,

                               ); //Color  0xFFFFFFFF

	g_font->DrawTextA(_spriteHandler,        //pSprite

								remainTimeString.str().c_str(),  //pString

								-1,          //Count

                                &font_rect3,  //pRect

                                DT_LEFT|DT_NOCLIP, 0xFFFFFFFF//Format,

                                ); //Color 0xFFFFFFFF
	g_font->Release();


}

void InfoBar::SetLife(int life)
{
	_life=life;
}

void InfoBar::SetPoint(int point)
{
	_point=point;
}